Skip to content

github-backup(drain): ack webhook events only after a successful fetch - #3290

Merged
dezren39 merged 1 commit into
mainfrom
github-backup/fix-drain-ack-3219
Nov 1, 2026
Merged

dezren39 merged 1 commit into
mainfrom
github-backup/fix-drain-ack-3219

Conversation

@dezren39

@dezren39 dezren39 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #3219

The bug

drain_queue.py appended every event id to the ack list up front and POSTed it to the Worker at the end of the run — including events whose fetch had just returned "fail" or "missing". The Worker deletes acked events from KV, so a transient fetch failure silently converted into up-to-a-week of staleness: the failure was written to no log, the 15-min coalesce stamp was advanced anyway, and the run summary printed the repo under fetched regardless of outcome.

The fix

An event is now acked only once the drainer has made the mirror reflect it:

  • Planned repo, fetch attempted: ack iff fetch_repo returned "ok". On "fail"/"missing" the event stays queued for the next drain tick, the failure is appended to fetch.log in the daily pass's leading format (plus drain context: oldest event age, consecutive-failure count), and the coalesce stamp is not advanced.
  • Planned repo inside its coalesce window: the event stays queued (not acked); a drain after the window passes fetches and acks it. Coalesce stamps are written only on success.
  • Unplanned repo: acked + fetch.log note — preserved behavior (mirror creation is the weekly reconcile's decision).
  • Retry guard: consecutive drain failures are counted per repo (state.json key drain_fail::<repo>). At 5 consecutive failures the failure is logged loudly (DRAIN-CHRONIC … event(s) kept queued, needs attention) and the run exits non-zero so systemd surfaces it — mirroring the daily pass's chronic-failure pattern. The event is kept, never silently dropped; a later success clears the counter.
  • Run summary now distinguishes fetched vs failed (with per-repo result + failure count) vs unplanned vs coalesced_pending, plus the acked count. plan.json is loaded once instead of per repo.

Tests — before / after

New regression test infra/github-backup/tests/test_drain_queue.py drives the real drain_queue.main() with a stub Worker + stub fetch_repo (same shape as the probe in #3219): 32 checks across success / fail / missing / unplanned / coalesce-window / coalesce-expired / chronic / recovery / mixed-batch cases.

Before (test run against the pre-fix drain_queue.py on this branch's base):

{"events": 1, "fetched": ["owner/repo"]}      <- summary claims success on a failed fetch
PASS success: exit 0
PASS success: event acked
PASS success: coalesce stamp set
PASS success: no fetch.log
FAIL fail: event NOT acked                     <- the bug: acked despite fetch failure
AssertionError: fail: event NOT acked

After:

32/32 checks passed

including: fail → not acked + fetch.log line with event age + no stamp + counter incremented; missing → same; coalesce window → not acked and no fetch attempted, fetched+acked once the window passes; 5th consecutive failure → exit 1 + DRAIN-CHRONIC in fetch.log + event still queued; success after failures clears the counter.

Run locally on the laptop: python3 infra/github-backup/tests/test_drain_queue.py.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Events were acked (deleted from the Worker KV queue) even when the
fetch failed or the mirror was missing, and the coalesce stamp was
advanced anyway — a transient failure silently became up to a week
of staleness with no log. Now: ack only on fetch ok; failures stay
queued, are appended to fetch.log with the oldest event age, and are
counted per repo; at 5 consecutive failures the run logs DRAIN-CHRONIC
and exits non-zero (event still kept). Coalesce-window events stay
queued until a drain fetches them. Unplanned repos keep the previous
behavior (acked + noted for the weekly reconcile).

Regression test: infra/github-backup/tests/test_drain_queue.py (32 checks).

Fixes #3219
@dezren39
dezren39 requested a review from a team as a code owner November 1, 2026 01:58
@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d06d9408-7e10-4a5a-996d-adcee8150cdc
Commits

Reviewing files that changed from the base of the PR and between cf1b243 and 50bf3c5.

Files selected for processing: 3
  • infra/github-backup/README.md
  • infra/github-backup/bin/drain_queue.py
  • infra/github-backup/tests/test_drain_queue.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T02:00:09.285780Z 50bf3c5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit 1a7366f into main Nov 1, 2026
1 check passed
@dezren39
dezren39 deleted the github-backup/fix-drain-ack-3219 branch November 1, 2026 02:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50bf3c579c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +147 to +148
failed.append({"repo": repo, "result": res,
"consecutive_failures": fs["count"]})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow queue polling to progress past retained failed events

If the queue contains 500 older events for unavailable planned mirrors, retaining those events now prevents later events for healthy repositories from being processed. The Worker in infra/github-backup/worker/src/index.js:55–61 returns only the first 500 entries and neither follows nor exposes a pagination cursor, so every drain retries the same failed batch until recovery or expiration of the seven-day TTL. I reproduced this with 500 missing-mirror events followed by one healthy-repository event: repeated drains never attempted the healthy repository. Preserve failed events, but add pagination or another mechanism that allows polling to advance past them.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

github-backup(drain): webhook events are acked even when the fetch failed or the mirror is missing — freshness signal silently dropped

1 participant